
import { Component, Emit, Prop } from 'vue-property-decorator';
import { BaseController, PageVO, DialogVO, YhRspType, YhResponseData, DateUtils } from '@yhfin/biz';
import { InvestMentReq } from '../model/InvestMentReq';
import InvestmentService from '../service/InvestmentService'
import { TableConfigVO, ColumnVO } from '@/common/vo';
import { dateFormat } from '@/utils/tools';
import RiskTable from '@/common/components/risk-table-plus.vue';

@Component({
    components: { RiskTable },
    watch: {
    }
})
export default class OperationRecordController extends BaseController {
    private dialogVO: DialogVO = new DialogVO();
    private service: InvestmentService = new InvestmentService();
    private reqVO: InvestMentReq = new InvestMentReq();
    tableConfig: TableConfigVO = {
        rowKey: 'punishNo', // 主键key
        allRowKeys: [], // 所有页数据的key集合
    };
    columns: ColumnVO[] = [
        {
            title: '操作人',
            field: 'ctUser',
            // filterType: 'search',
            // filters: [{ datas: '' }],
            minWidth: 100,
        },
        {
            title: '操作日期',
            field: 'ctDate',
            // filterType: 'search',
            // filters: [{ datas: '' }],
            minWidth: 100,
            render: value => dateFormat(value) || '--'
        },
        {
            title: '导入产品',
            field: 'controlGrade',
            // filterType: 'search',
            // filterField: 'codeOrName',
            // filters: [{ datas: '' }],
            minWidth: 100,
            render: (value, record) => record.fundCode + '(' + record.fundName + ')'
        },
    ]
    tableLoading: boolean = false;
    tableKey: number = 0;
    paging: any = { pageSize: 25, currentPage: 1, total: 0 };
    searchParams: any = {
        ctUser: '',
        ctDate: '',
        codeOrName: '',
    }


    open() {
        this.dialogVO = new DialogVO().getUpdateDialog('操作记录');
        this.search();
    }

    search() {
        this.pageQuery();
    }

    private pageQuery() {
        this.tableLoading = true;
        this.service.operateByUser({ paging: this.paging, ...this.searchParams }).then(res => {
            this.$nextTick(() => {
                this.$set(this.pageVO, 'list', res.list);
                this.paging.total = res.total;
                console.info(this.pageVO)
            })
        }).finally(() => {
            this.tableLoading = false;
        })
    }

    getDateStr(row) {
        if (row && row.ctDate) {
            // 20240521
            const y = row.ctDate.substr(0, 4);
            const m = row.ctDate.substr(4, 2)
            const d = row.ctDate.substr(6, 2)
            return y + '-' + m + '-' + d;
        }
    }

    handleSearch(): void {
        this.paging.currentPage = 1;
        this.pageQuery();
    }
}
